/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipo.mm.ejb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author makcro
 */
@Entity
@Table(name = "REPRESENTATIVE")
@NamedQueries({@NamedQuery(name = "Representative.findAll", query = "SELECT r FROM Representative r WHERE r.deleted = false order by r.lastName"),
    @NamedQuery(name = "Representative.findById", query = "SELECT r FROM Representative r WHERE r.id = :id"),
    @NamedQuery(name = "Representative.findByFirstName", query = "SELECT r FROM Representative r WHERE r.firstName = :firstName"),
    @NamedQuery(name = "Representative.findByLastName", query = "SELECT r FROM Representative r WHERE r.lastName = :lastName"),
    @NamedQuery(name = "Representative.findByEmail", query = "SELECT r FROM Representative r WHERE r.email = :email"),
    @NamedQuery(name = "Representative.findByTelephone", query = "SELECT r FROM Representative r WHERE r.telephone = :telephone"),
    @NamedQuery(name = "Representative.findByFax", query = "SELECT r FROM Representative r WHERE r.fax = :fax"),
    @NamedQuery(name = "Representative.findByFunction", query = "SELECT r FROM Representative r WHERE r.function = :function"),
    @NamedQuery(name = "Representative.findByNote", query = "SELECT r FROM Representative r WHERE r.note = :note"),
    @NamedQuery(name = "Representative.findByDeleted", query = "SELECT r FROM Representative r WHERE r.deleted = :deleted"),
    @NamedQuery(name = "Representative.findSimilar", query="SELECT r FROM Representative r WHERE r.deleted = false AND r.firstName LIKE :firstName AND r.lastName LIKE :lastName AND " +
    "r.institution = :institution"),
    
    @NamedQuery(name = "Representative.search",
        query = "SELECT r FROM Representative r WHERE " +
        "(r.firstName LIKE :query OR " +
        "r.lastName LIKE :query OR " +
        "r.institution.name LIKE :query) " +
        "AND r.deleted = false"
    )
})
public class Representative implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Column(name = "FirstName")
    private String firstName;
    @Column(name = "LastName")
    private String lastName;
    @Column(name = "Email")
    private String email;
    @Column(name = "Telephone")
    private String telephone;
    @Column(name = "Fax")
    private String fax;
    @Column(name = "Function")
    private String function;
    @Column(name = "Note")
    private String note;
    @Basic(optional = false)
    @Column(name = "Deleted")
    private boolean deleted;
    @ManyToMany(mappedBy = "representativeCollection", fetch = FetchType.EAGER)
    private Collection<Meeting> meetingCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "organizer", fetch = FetchType.EAGER)
    private Collection<Meeting> meetingCollection1;
    @JoinColumn(name = "Institution", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Institution institution;
    @JoinColumn(name = "User", referencedColumnName = "Username")
    @ManyToOne(optional = false)
    private User user;

    public Representative() {
    }

    public Representative(Integer id) {
        this.id = id;
    }

    public Representative(Integer id, boolean deleted) {
        this.id = id;
        this.deleted = deleted;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getFunction() {
        return function;
    }

    public void setFunction(String function) {
        this.function = function;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public Collection<Meeting> getMeetingCollection() {
        return meetingCollection;
    }

    public void setMeetingCollection(Collection<Meeting> meetingCollection) {
        this.meetingCollection = meetingCollection;
    }

    public Collection<Meeting> getMeetingCollection1() {
        return meetingCollection1;
    }

    public void setMeetingCollection1(Collection<Meeting> meetingCollection1) {
        this.meetingCollection1 = meetingCollection1;
    }

    public Institution getInstitution() {
        return institution;
    }

    public void setInstitution(Institution institution) {
        this.institution = institution;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Representative)) {
            return false;
        }
        Representative other = (Representative) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.ipo.mm.ejb.entities.Representative[id=" + id + "]";
    }
}
